package com.Lixiaoqian.Gulangyu.ar_m.ui

import android.os.Bundle
import android.view.View.GONE
import com.Lixiaoqian.Gulangyu.base.BaseActivity
import com.Lixiaoqian.Gulangyu.utils.StatusBarUtils
import com.Lixiaoqian.Gulangyu.utils.ToastUtils
import com.wikitude.architect.ArchitectJavaScriptInterfaceListener
import com.wikitude.architect.ArchitectStartupConfiguration
import com.wikitude.architect.ArchitectView
import com.wikitude.common.camera.CameraSettings
import kotlinx.android.synthetic.main.layout_base.*

/**
 * Created by huangzhibo on 2018-02-26.
 * mail:1043202454@qq.com
 */
abstract class AbstractCamActivity : BaseActivity() {
    lateinit var arvichterView: ArchitectView
    override fun barRightEvent() {
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        wd_toolbar.isShowToolBar(GONE)
        StatusBarUtils.fullSrcAndNoHideBar(this)
    }

    fun initAR() {
        arvichterView = getArWidget()
        if (!ArchitectView.isDeviceSupported(this)) {
            ToastUtils.showLong("硬件不支持")
            finish()
        } else {
            val configuration = ArchitectStartupConfiguration().apply {
                this.features = getArFeatures()
                this.licenseKey = getArLicenseKey()
                this.cameraPosition = getArCameraPosi()
            }
            arvichterView.onCreate(configuration)
            arvichterView.addArchitectJavaScriptInterfaceListener(getUrlListener())
        }
    }

    override fun onPostCreate(savedInstanceState: Bundle?) {
        super.onPostCreate(savedInstanceState)
        arvichterView.onPostCreate()
        arvichterView.load(getWorldUrl())
    }

    override fun onResume() {
        super.onResume()
        arvichterView.onResume()
    }

    override fun onPause() {
        super.onPause()
        arvichterView.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        arvichterView.onDestroy()
    }

    /*--------------抽象fun-----------------*/
    abstract fun getArWidget(): ArchitectView

    abstract fun getArFeatures(): Int

    abstract fun getArLicenseKey(): String

    abstract fun getArCameraPosi(): CameraSettings.CameraPosition

    abstract fun getWorldUrl(): String

    abstract fun getUrlListener(): ArchitectJavaScriptInterfaceListener
}